#########################################################################
# Title 	 : Graphical display of # of arms and planned sample size
# Manuscript Ref : Figure 4 of the manuscript
# Version	 : R version 3.6.3 (2020-02-29)
###########################################################################
library(tidyverse)
library(ggpubr)
library(ggplot2)
library(ggalt)
library(RColorBrewer)
library(cowplot) 	

# setwd(" ") # set path of your working directory for file export

#---------------------------------------------------------------
# The following data is presented on Table 1 of the mansucript
#---------------------------------------------------------------
dat <- dput( structure(list(stype = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L), .Label = c("Case-control", "Case series", "Cohort / non-randomised", 
"Quasi-randomised", "RCT"), class = "factor"), Dgroup = structure(c(2L, 
12L, 1L, 1L, 20L, 1L, 23L, 1L, 1L, 2L, 3L, 1L, 18L, 1L, 1L, 2L, 
12L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 1L, 7L, 1L, 8L, 
1L, 9L, 1L, 1L, 10L, 1L, 11L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 13L, 1L, 1L, 15L, 1L, 16L, 1L, 18L, 
1L, 1L, 1L, 1L, 1L, 21L, 1L, 1L, 1L, 1L, 1L, 1L, 24L, 1L, 1L, 
1L, 1L, 1L, 2L, 12L, 1L, 9L, 1L, 1L, 2L, 12L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 4L, 1L, 5L, 1L, 
1L, 6L, 1L, 1L, 1L, 1L, 8L, 1L, 9L, 1L, 1L, 10L, 1L, 1L, 11L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 13L, 1L, 1L, 14L, 1L, 1L, 15L, 1L, 1L, 1L, 16L, 1L, 
17L, 1L, 18L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 19L, 1L, 
1L, 22L, 1L, 21L, 1L, 1L, 1L, 1L, 1L, 1L, 23L, 1L, 25L, 1L, 1L, 
1L, 1L, 1L), .Label = c("", "ALL", "Angiotensin receptor modulator", 
"Anti-gout", "Antiallergic", "Antibiotic", "Anticoagulant", "Antifungal", 
"Antimalarial", "Antioxidant", "Antiviral", "ATMP", "Corticosteroids", 
"Herbal Syrup", "Immunostimulatory", "Immunosuppressive", "Kinase inhibitor", 
"Monoclonal antibodies", "Mucolytic agent", "Non-malarial antiparasitic", 
"Non-specific anti-inflammatory or immunosuppressive", "NSAIDs", 
"Protease Inhibitor", "Sigma receptor modulator", "Unable to classify"
), class = "factor"), DGname = structure(c(6L, 19L, 89L, 5L, 
94L, 122L, 105L, 130L, 31L, 6L, 9L, 1L, 91L, 117L, 37L, 6L, 19L, 
89L, 43L, 69L, 32L, 132L, 133L, 73L, 61L, 87L, 12L, 33L, 13L, 
63L, 14L, 104L, 15L, 35L, 68L, 16L, 136L, 17L, 112L, 84L, 74L, 
23L, 45L, 100L, 123L, 83L, 134L, 58L, 21L, 98L, 60L, 55L, 109L, 
42L, 41L, 62L, 70L, 125L, 71L, 59L, 91L, 126L, 26L, 53L, 114L, 
88L, 95L, 25L, 57L, 78L, 118L, 106L, 116L, 115L, 97L, 135L, 51L, 
48L, 107L, 6L, 19L, 90L, 15L, 68L, 108L, 6L, 19L, 93L, 132L, 
43L, 89L, 120L, 66L, 131L, 69L, 34L, 110L, 75L, 72L, 133L, 121L, 
9L, 85L, 10L, 38L, 11L, 128L, 52L, 12L, 22L, 30L, 13L, 56L, 14L, 
76L, 15L, 68L, 35L, 16L, 136L, 7L, 17L, 112L, 84L, 74L, 58L, 
134L, 109L, 100L, 46L, 111L, 98L, 18L, 24L, 119L, 36L, 44L, 45L, 
129L, 23L, 80L, 42L, 41L, 47L, 64L, 40L, 39L, 70L, 125L, 82L, 
103L, 71L, 124L, 79L, 113L, 91L, 126L, 114L, 127L, 26L, 101L, 
54L, 3L, 4L, 29L, 77L, 92L, 2L, 28L, 99L, 96L, 95L, 102L, 118L, 
8L, 49L, 86L, 81L, 105L, 130L, 135L, 67L, 27L, 50L, 20L, 65L), .Label = c("ACE inhibitor", 
"Acetylcysteine", "Adalimumab", "Adamumab(Qletli)", "Aerosol inhalation of vMIP: viral macrophage inflammatory protein", 
"ALL", "Alpha-lipoic acid", "Anakinra", "Angiotensin receptor modulator", 
"Anti-gout", "Antiallergic", "Antibiotic", "Anticoagulant", "Antifungal", 
"Antimalarial", "Antioxidant", "Antiviral", "ASC09", "ATMP", 
"Aviptadil", "Azatanavir", "Azithromycin", "Azvudine", "Baloxavir marboxil", 
"Baricitinib", "Bevacizumab", "Bismuth potassium citrate", "Bromhexine hydrochloride", 
"Camrelizumab", "Carriomycin", "Case-Cotrol Studies", "CAStem cells", 
"Ceftriaxone", "Cell exosomes", "Chloroquine", "Cobicistat", 
"Cohort / Non-randomised Studies", "Colchicine", "Coroguard", 
"Corostop", "Corticosteroid_not specified", "Corticosteroids", 
"Covalescent plasma treatment", "Daclastavir", "Danoprevir", 
"Darunavir", "Dexamethasone", "diagnostic antifungal therapy", 
"Diammonium glycyrrhizinate", "Dipyridamole", "drug intervention", 
"Ebastine", "Eculizumab", "Emapalumab", "Emtricitabine", "Enoxaparin Sodium", 
"Escin", "Favipiravir", "Fingolimod", "Fludase", "gamma-Globulin", 
"Glucocorticoid", "Heparin", "Herbal Syrup", "Hormone", "Human menstrual blood-derived stem cells", 
"Hydrogen peroxide", "Hydroxychloroquine", "Immunoglobulin from cured patients", 
"Immunostimulatory", "Immunosuppressive", "Inactivated Mycobacterium vaccine", 
"Interferon ?1b", "Interferons", "Interleukin-2", "Itraconazole", 
"Ixekizumab", "Jacketinib hydrochloride", "Kinase inhibitor", 
"Ledispavir", "Leflunomile", "Leukine", "LL-37 antiviral peptide", 
"Lopinavir", "Losartan", "Macrophages suppression therapy", "Mechanical preventive anticoagulation", 
"Mepolizumab", "Mesenchymal Stem Cells", "Micro-ecological preparation", 
"Monoclonal antibodies", "Mucolytic agent", "NK Cells", "Non-malarial antiparasitic", 
"Non-specific anti-inflammatory or immunosuppressive", "Nonsteroidal anti-inflammatory drug", 
"Noscapine", "Novaferon", "NSAIDs", "Oseltamivir", "PD-1 blocking antibody", 
"Pirfenidone", "Polyinosinic-polycytidylic acid", "Prophylactic antifungal therapy", 
"Protease Inhibitor", "Pulmonary arterial hypertension agent", 
"Quasi-randomised Stuides", "Randomised Controlled Trials", "Remdesivir", 
"rhG-CSF", "Ribavirin", "Ritonavir", "Ruxolitinib", "Sarilumab", 
"Sigma receptor modulator", "Sildenafil citrate", "Siltuximab", 
"Sodium Escinate", "Sofosbuvir", "Standard Plasma", "Stem Cell Educator", 
"Suramin sodium", "Tenofovir", "Thalidomide", "Thymosin", "Tocilizumab", 
"Tozumab", "Tranilast", "Triazavirin", "Ulinastatin", "Umbilical cord blood mononuclear cells", 
"Umbilical Cord Mesenchymal Stem Cells", "Umbilical cord Wharton? Jelly derived mesenchymal stem cells", 
"Umifenovir", "Unable to classify", "Vitamin C"), class = "factor"), 
    Nstudy = c(4, 2, 1, 1, 1, 1, 1, 1, NA, 2, 1, 1, 1, 1, NA, 
    57, 16, 5, 4, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 4, 
    5, 1, 1, 21, 13, 10, 6, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 3, 2, 1, 1, 1, 1, 1, 7, 3, 1, 1, 1, 1, 4, 2, 1, 1, 1, 
    1, 1, 1, 1, 2, 1, 1, NA, 2, 1, 1, 1, 1, NA, 178, 29, 3, 6, 
    7, 5, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 
    5, 4, 1, 2, 2, 1, 1, 44, 33, 17, 6, 4, 2, 70, 33, 32, 24, 
    11, 13, 10, 3, 3, 3, 2, 3, 2, 2, 1, 1, 1, 1, 1, 1, 8, 7, 
    1, 1, 1, 1, 5, 3, 1, 1, 2, 2, 1, 1, 16, 6, 5, 1, 1, 1, 1, 
    1, 1, 1, 1, 3, 2, 1, 1, 1, 9, 3, 1, 2, 1, 1, 1, 1, 1, 5, 
    1, 1, 1, 1, 1), Narm_total = c(4, 2, 1, 1, 1, 1, 1, 1, NA, 
    3, 1, 1, 2, 2, NA, 78, 19, 6, 4, 3, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 1, 11, 6, 5, 1, 1, 30, 18, 15, 9, 3, 3, 2, 1, 
    1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 1, 1, 1, 7, 3, 1, 1, 
    1, 1, 5, 2, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, NA, 2, 1, 1, 1, 
    1, NA, 293, 38, 7, 7, 7, 5, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 
    2, 2, 2, 2, 2, 1, 1, 5, 4, 1, 2, 2, 1, 1, 64, 46, 19, 6, 
    4, 2, 134, 56, 50, 36, 19, 18, 15, 9, 5, 5, 4, 3, 2, 2, 1, 
    1, 1, 1, 1, 1, 11, 10, 1, 1, 1, 1, 8, 5, 2, 1, 2, 2, 1, 1, 
    22, 9, 6, 1, 1, 1, 1, 1, 1, 1, 1, 4, 3, 1, 1, 1, 10, 3, 2, 
    2, 1, 1, 1, 1, 1, 5, 1, 1, 1, 1, 1), Narm_ss = c(4, 2, 1, 
    1, 1, 1, 1, 1, NA, NA, NA, NA, NA, NA, NA, 62, 17, 6, 4, 
    1, 1, 1, 1, 1, 1, 1, NA, NA, 1, 1, 1, 1, 10, 6, 4, 1, 1, 
    25, 16, 13, 7, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, NA, 3, 2, 
    1, NA, NA, NA, NA, 4, 2, 1, NA, NA, 1, 1, NA, NA, 1, NA, 
    1, 1, NA, NA, 3, 2, 1, NA, 2, 1, 1, 1, 1, NA, 173, 29, 1, 
    6, 7, 5, 3, 2, 1, NA, 1, 1, 1, 1, 1, NA, 2, 2, 1, 1, 2, 1, 
    1, 1, NA, 1, 2, 2, NA, NA, 29, 15, 14, 4, 2, 2, 75, 29, 28, 
    20, 15, 9, 2, NA, 1, 5, 4, 1, 2, 1, NA, 1, 1, 1, 1, NA, 4, 
    4, NA, 1, 1, 1, 5, 4, NA, 1, NA, NA, 1, 1, 10, 5, NA, 1, 
    NA, NA, 1, 1, 1, 1, 1, 3, 3, NA, NA, NA, 9, 3, 2, 1, 1, 1, 
    1, 1, 1, 4, 1, 1, 1, NA, 1), Npat_total = c(110, 70, 30, 
    40, 20, 20, 20, 20, NA, NA, NA, NA, NA, NA, NA, 3330, 634, 
    150, 99, 5, 20, 10, 5, 300, 5, 40, NA, NA, 80, 80, 130, 130, 
    397, 252, 145, 500, 500, 914, 740, 709, 348, 80, 31, 70, 
    60, 10, 196, 50, 50, 10, 4, 60, NA, 122, 72, 50, NA, NA, 
    NA, NA, 500, 460, 20, NA, NA, 20, 16, NA, NA, 16, NA, 10, 
    10, NA, NA, 226, 96, 130, NA, 204, 150, 150, 54, 54, NA, 
    38445, 1072, 10, 151, 345, 178, 155, 28, 15, NA, 30, 100, 
    40, 30, 20, NA, 390, 390, 3000, 3000, 80, 30, 50, 260, 0, 
    260, 60, 60, NA, NA, 24765, 13549, 11216, 601, 370, 231, 
    6950, 2905, 3130, 2142, 655, 1005, 906, NA, 40, 186, 300, 
    80, 20, 35, NA, 35, 30, 120, 10, NA, 224, 224, NA, 75, 75, 
    75, 160, 140, NA, 20, NA, NA, 35, 35, 472, 334, NA, 30, NA, 
    NA, 18, 30, 30, 40, 20, 166, 166, NA, NA, NA, 390, 187, 40, 
    18, 30, 15, 100, 50, 50, 430, 20, 170, 230, 0, 10)), row.names = c(NA, 
186L), class = "data.frame"))

#-------------------------------------------------
# Keep only Cohorts and RCTs for Figure 4
#-------------------------------------------------
drug_table <- dat[which(dat$stype %in% c("Cohort / non-randomised","RCT")),]

# Keep the rows describing the overall drug categories
drug_table <- drug_table[which(drug_table$Dgroup!=""),]
drug_table <- drug_table[which(drug_table$Dgroup!="ALL"),]
drug_table <-droplevels(drug_table )

# Create subset data frames for cohorts and RCTs separately
drug_cohort <- drug_table[which(drug_table$stype %in% c("Cohort / non-randomised")),]
drug_rct	<- drug_table[which(drug_table$stype %in% c("RCT")),]
drug_cohort <-droplevels(drug_cohort)
drug_rct	<-droplevels(drug_rct)

###########################################################################
## Generate plots for showing number of arms and planned sample sizes
###########################################################################

#------------------------------------
# Cohort studies : Number of arms
#------------------------------------
a <- ggdotchart(drug_cohort, 
			x 		= "Dgroup",
			y 		= "Narm_total",
			facet.by	= "stype",
			color		= "#00AFBB",
      	     add		= "segments",                        
	           rotate		= TRUE,                              
	           dot.size	= 6,                                 
      	     label 		= drug_cohort$Narm_total,            
	           font.label = list(color = "white", size = 9, 
                             vjust = 0.5),               
           ggtheme = theme_pubr()                        
           )+
	ylab("Number of study arms") +
	ylim(0,150)+
	xlab("")+
	ggtitle("")+
		theme(axis.text.x = element_text(size=8, angle=0),
		          axis.text.y = element_text(size=8),
			 axis.title=element_text(size=14,face="bold"))

#------------------------------------
# RCTs : Number of arms
#------------------------------------
b <- ggdotchart(drug_rct, 
			x		= "Dgroup",
			y		= "Narm_total",
			facet.by	= "stype",
			color		= "#00AFBB",
      	     add		= "segments",                             
	           rotate		= TRUE,                                
	           dot.size	= 6,                                 
      	     label		= drug_rct$Narm_total,                  
	           font.label	= list(color = "white", size = 9, 
                             vjust = 0.5),              
           ggtheme = theme_pubr()                       
           )+
	ylab("Number of study arms") +
	ylim(0,150)+
	xlab("")+
	ggtitle("")+
		theme(axis.text.x = element_text(size=8, angle=0),
		          axis.text.y = element_text(size=8),
			 axis.title=element_text(size=14,face="bold"))

#--------------------------------------
# Cohort studies : Planned sample size
#--------------------------------------
drug_cohort_b <- drug_cohort[which(drug_cohort$Npat_total >0),]
drug_cohort_b <- droplevels(drug_cohort_b )

c <- ggdotchart(drug_cohort_b, 
			x		= "Dgroup",
			y		= "Npat_total",
			facet.by	= "stype",
			color		= "#00AFBB",
      	     add		= "segments",                           
	           rotate		= TRUE,                                
	           dot.size	= 6,                                
      	     label		= drug_cohort_b$Npat_total,                      
	           font.label	= list(color = "white", size = 9, 
                             vjust = 0.5),               
           ggtheme = theme_pubr()                        
           )+
	ylab("Planned sample size") +
	ylim(0,1500)+
	xlab("")+
	ggtitle("")+
		theme(axis.text.x = element_text(size=8, angle=0),
		          axis.text.y = element_text(size=8),
			 axis.title=element_text(size=14,face="bold"))

#--------------------------------------
# RCTs : Planned sample size
#--------------------------------------
drug_rct_b <- drug_rct[which(drug_rct$Npat_total >0),]
drug_rct_b <- droplevels(drug_rct_b )

d <- ggdotchart(drug_rct_b, 
			x = "Dgroup",
			y = "Npat_total",
			facet.by="stype",
			gap=c(10000,20000),
			color="#00AFBB",
      	     add = "segments",                            
	           rotate = TRUE,                               
	           dot.size = 9,                                
      	     label = drug_rct_b$Npat_total,               	
	           font.label = list(color = "white", size = 9, 
                             vjust = 0.5),               
           ggtheme = theme_pubr()                        
           )+
	ylab("Planned sample size") +
	ylim(0,30000)+
	xlab("")+
	ggtitle("")+
		theme(axis.text.x = element_text(size=8, angle=0),
		          axis.text.y = element_text(size=8),
			 axis.title=element_text(size=14,face="bold"))

###########################################################################################
# Use cowplot libray to create a 2 by 2 panel & export as high resolution graph (600 dpi)
###########################################################################################

tiff(file="Figure_5.tiff", 
            width=34, 
		height=24, 
		units="cm", 
            pointsize="13", 
		compression = "lzw+p", 
            bg="white",
		res=600, 
		antialias = "none"
	)

plot_grid(a,b,c,d)

dev.off() # End export

# Break in x-axis on bottom right panel presented on final manuscript is created post-exporting
# Digital manipualtion after export was done using GimP software (https://www.gimp.org/)

# End
